package com.wang.learn.domain.resource.model;

import com.wang.learn.common.domain.BaseEntity;
import com.wang.learn.common.model.EnableEnum;
import lombok.Getter;
import lombok.ToString;

import java.util.List;

/**
 * @author : wcz
 * @version V1.0
 * @Description: 资源实体
 */
@Getter
@ToString
public class Resource extends BaseEntity<Resource> {

    /**
     * 资源编号
     */
    private String resourceNo;
    /**
     * 资源类型
     */
    private ResourceType resourceType;

    /**
     * 资源名称
     */
    private String resourceName;
    /**
     * 前端路由
     */
    private String router;

    /**
     * url
     */
    private String template;

    /**
     * 排序字段
     */
    private Integer sortNo;
    /**
     * 是否可用
     */
    private EnableEnum enableFlag;
    /**
     * 图标
     */
    private String iconClass;

    /**
     * 备注
     */
    private String mark;

    /**
     * 平台Id
     */
    private Long plantId;
    /**
     * 父权限Id;
     */
    private Long parentId;

    /**
     * 子权限Id集合
     */
    private List<Long> subResources;

    /**
     * 权限级别
     */
    private ResourceLevel level;

    private Resource(Builder tBuilder) {
        this.resourceNo = tBuilder.resourceNo;
        this.resourceType = tBuilder.resourceType;
        this.resourceName = tBuilder.resourceName;
        this.router = tBuilder.router;
        this.template = tBuilder.template;
        this.sortNo = tBuilder.sortNo;
        this.iconClass = tBuilder.iconClass;
        this.mark = tBuilder.mark;
        this.plantId = tBuilder.plantId;
        this.parentId = tBuilder.parentId;
        this.subResources = tBuilder.subResources;
        this.level = tBuilder.level;
    }

    public static final class Builder {
        private String resourceNo;
        private ResourceType resourceType;
        private String resourceName;
        private String router;
        private String template;
        private Integer sortNo;
        private EnableEnum enableFlag;
        private String iconClass;
        private String mark;
        private Long plantId;
        private Long parentId;
        private List<Long> subResources;
        private ResourceLevel level;
        private Builder() {
        }

        public Builder resourceNo(String val) {
            resourceNo = val;
            return this;
        }
        private Builder resourceType(ResourceType val){
            resourceType = val;
            return this;
        }
        public Resource build(){
            return new Resource(this);
        }

        public static Builder newInstance(ResourceType resourceType) {
            Builder builder = new Builder();
            builder.resourceType(resourceType);
            return builder;
        }
    }

    public static void main(String[] args) {
        Resource build = Builder.newInstance(ResourceType.MENU).resourceNo("123").build();
        System.out.println(build);
    }
}
